package com.example.user.util;

public class BuilderDemo {

    public static void main(String[] args) {
        Computer computer = new Computer.Builder().setKeyboard("ewr").setUsbCount("哦i技术都").build();
        System.out.println(computer);
    }

}

class Computer {
    private String cpu;//必须
    private String ram;//必须

    private Computer(Builder builder) {
        this.cpu = builder.cpu;
        this.ram = builder.ram;
    }

    @Override
    public String toString() {
        return "Computer{" +
                "cpu='" + cpu + '\'' +
                ", ram='" + ram + '\'' +
                '}';
    }

    public static final class Builder {
        private String cpu;//必须
        private String ram;//必须

        public Builder() {
        }

        public Builder setUsbCount(String cpu) {
            this.cpu = cpu;
            return this;
        }

        public Builder setKeyboard(String ram) {
            this.ram = ram;
            return this;
        }

        public Computer build() {
            return new Computer(this);
        }
    }
}

